package com.antu.first.util;

import org.apache.http.HttpResponse;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 短信生成工具
 * Created by ${TangChao} on 2018-01-29 11:55.
 */
@Component
public class PhoneCode {

    public String code(String u_phone) {
        String host = "https://fesms.market.alicloudapi.com";
        String path = "/sms/";
        String method = "GET";
        //若接口短息用完了 就在阿里云去买，代码无所谓，主要是接口，接口买好后把下面appcode码换成阿里收到appcode码
        String appcode = "c6a96c17c7e64e6197981c9ac93e21c2";
        String i =""+((Math.random()*9+1)*100000);
        int n = (new Double(i)).intValue();
        String code = Integer.toString(n);
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("code", code);
        querys.put("phone", u_phone);
        querys.put("skin", "1");
         try {
            HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("code"+code);
        return code;
    }
}
